<template>
	<view class="home-query">
		<view class="home-query-header flexR">
			<image src="../../../static/images/baner/1.png" mode="scaleToFill"></image>
			{{type==2?'出院带药':'手术'}}信息查询
		</view>
		<view class="sawtooth bg-light">
			<image src="../../../static/images/imgs/sawtooth.png" mode="scaleToFill"></image>
		</view>
		<view class="home-query-main flexR">
			<label>身份证号</label>
			<view>
				<u-input v-model="sfzh" trim maxlength="18"/>
			</view>
		</view>
		<view style="padding: 0 30rpx;height: 90rpx;" @click="onQuery">
			<view class="theme-light-btn">
				<u-icon name="search"></u-icon>
				查询
			</view>
		</view>
		<view class="reminder">
			<view class="reminder-title">
				温馨提示
			</view>
			<view class="reminder-content">
				查询当前本院的{{type==2?'出院带药':'手术'}}信息
			</view>
		</view>
		<view class="home-query-main" v-show="dataList.length">
			<u-cell-group>
				<u-cell-item :title="item.syxh" v-for="(item, i) in dataList" :key='i' @click='toPage(item)'></u-cell-item>
			</u-cell-group>
		</view>
		<Load :load="load" />
	</view>
</template>

<script>
	import { getTakeMedicine, getOperation } from '@/api/home.js'
	import Load from '@/components/Load/index.vue'
	export default {
		components:{ Load },
		data() {
			return {
				type:'1' ,// 1 手术信息 2 出院带药
				load:false,
				sfzh:'',
				dataList:[]
			}
		},
		onLoad(op) {
			if(op.type){
				this.type = op.type
			}
		},
		methods: {
			onQuery(){
				if(!this.sfzh){
					this.$u.toast('请输入身份证号')
					return
				}
				let params = {
					sfzh: this.sfzh,
					sfzy:0
				}
				this.load = true
				if(this.type==1){
					getOperation(params).then(data => {
						this.load = false
						if(data.length){
							this.dataList = data
						}else{
							this.dataList = []
							this.$u.toast('暂未查询到该身份证号下的手术信息')
						}
					}).catch(e => {
						this.dataList = []
						this.load = false
					})
				}else{
					getTakeMedicine(params).then(data => {
						this.load = false
						if(data.length){
							this.dataList = data
						}else{
							this.dataList = []
							this.$u.toast('暂未查询到该身份证号下的出院带药信息')
						}
					}).catch(e => {
						this.dataList = []
						this.load = false
					})
				}
			},
			toPage(item){
				let res = JSON.stringify(item)
				if(this.type==1){
					uni.navigateTo({
						url:'/pages/Home/Operation/index?params=' + res
					})
				}else{
					uni.navigateTo({
						url:'/pages/Home/Medicine/index?params=' + res
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home-query{
		height: calc(100vh);
		overflow: scroll;
		background-color: $uni-bg-color;
		&-header{
			padding: 50rpx 30rpx 30rpx 30rpx;
			>image{
				height: 90rpx;
				width: 90rpx;
				margin-right: 30rpx;
			}
			font-size: 40rpx;
			align-items: center;
			font-weight: bold;
			color: #FFF;
			background-color: $theme-color-light;
		}
	}
</style>
<style lang="scss">
	.home-query-main{
		align-items: center;
		padding: 30rpx;
		>label{
			color: $text-color-grey;
		}
		>view{
			margin-left: 10rpx;
			flex: 1;
			border: 1px solid $border-color;
			border-radius: 30px;
			height: 40px;
			display: flex;
			align-items: center;
			padding: 0 10px;
			input{
				min-height: 30px !important;
				height: 30px;
				padding: 0;
			}
		}
	}
</style>